package org.cnc.explain.lifecycle.hookbean;

import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * <p>
 * #TODO: desc
 * </p>
 *
 * @author zhiyong.tan
 * @since 2022-09-14
 */
@Component
public class HookInstantiationAwareBeanPostProcessor implements InstantiationAwareBeanPostProcessor {
	@Override
	public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
		if (PrintHelper.beanNameSatisfied(beanName)) {
			PrintHelper.printMsgWithStep("执行 InstantiationAwareBeanPostProcessor#postProcessBeforeInstantiation 回调");
		}

		return InstantiationAwareBeanPostProcessor.super.postProcessBeforeInstantiation(beanClass, beanName);
	}

	@Override
	public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
		if (PrintHelper.beanNameSatisfied(beanName)) {
			PrintHelper.printMsgWithStep("执行 InstantiationAwareBeanPostProcessor#postProcessAfterInstantiation 回调");
		}
		return InstantiationAwareBeanPostProcessor.super.postProcessAfterInstantiation(bean, beanName);
	}

	@Override
	public PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName) throws BeansException {
		if (PrintHelper.beanNameSatisfied(beanName)) {
			PrintHelper.printMsgWithStep("执行 InstantiationAwareBeanPostProcessor#postProcessProperties 回调");
		}
		return InstantiationAwareBeanPostProcessor.super.postProcessProperties(pvs, bean, beanName);
	}
}
